load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("//tools:defaults.bzl", "ng_module", "ng_package", "ng_test_library", "ng_web_test_suite")

package(default_visibility = ["//visibility:public"])

ng_module(
    name = "material-moment-adapter",
    srcs = glob(
        ["**/*.ts"],
        exclude = ["**/*.spec.ts"],
    ),
    module_name = "@angular/material-moment-adapter",
    # We need a custom tsconfig that allows synthetic default imports. This is
    # because "moment" does not have a typed default import.
    tsconfig = ":tsconfig",
    deps = [
        "//src:dev_mode_types",
        "//src/material/core",
        "@npm//@angular/core",
        "@npm//moment",
    ],
)

ts_config(
    name = "tsconfig",
    src = "tsconfig-build.json",
    deps = ["//src:bazel-tsconfig-build.json"],
)

ng_test_library(
    name = "unit_test_sources",
    srcs = glob(
        ["**/*.spec.ts"],
        exclude = ["**/*.e2e.spec.ts"],
    ),
    deps = [
        ":material-moment-adapter",
        "//src/material/core",
        "//src/material/testing",
        "@npm//moment",
    ],
)

ng_web_test_suite(
    name = "unit_tests",
    # We need to load Moment statically since it is not a named AMD module and needs to
    # be manually configured through "require.js" which is used by "karma_web_test_suite".
    static_files = [
        "@npm//moment",
    ],
    deps = [
        ":require-config.js",
        ":unit_test_sources",
    ],
)

ng_package(
    name = "npm_package",
    srcs = ["package.json"],
    entry_point = ":public-api.ts",
    tags = ["release-package"],
    deps = [":material-moment-adapter"],
)
